package com.steel.yfmall.cloud.assistant.goods.impl;

import com.steel.yfmall.cloud.assistant.goods.ProductChannelGoodsPriceService;
import com.steel.yfmall.cloud.assistant.dto.para.goods.ParaProductChannelGoodsPriceBean;
import com.steel.yfmall.cloud.assistant.goods.mapper.ProductChannelGoodsPriceMapper;
import com.steel.yfmall.cloud.assistant.po.goods.ProductChannelGoodsPrice;
import com.steel.yfmall.cloud.assistant.po.goods.ProductChannelGoodsPriceExample;
import com.steel.yfmall.cloud.components.utils.utils.UtilDate;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author yuchaohua
 * @version V1.0
 * @Title: ProductChannelGoodsPriceServiceImpl
 * @Package com.steel.yfmall.cloud.assistant.biz.service.goods.impl
 * @Description: (用一句话描述该文件做什么)
 * @date 2020/12/10 1:17
 */
@Service
@Slf4j
public class ProductChannelGoodsPriceServiceImpl implements ProductChannelGoodsPriceService {

    @Resource
    private ProductChannelGoodsPriceMapper productChannelGoodsPriceMapper;

    /**
     * 修改商品价格信息
     * @Title: updateProductChannelGoodsPrice
     * @Description: (这里用一句话描述这个方法的作用)
     * @Param paraBean 参数说明
     * @Param recordBean 参数说明
     * @return boolean    返回类型
     * @author yuchaohua
     * @date 2020/12/10 1:21
     */
    @Override
    public boolean updateProductChannelGoodsPrice(ParaProductChannelGoodsPriceBean paraBean, ProductChannelGoodsPrice recordBean) {
        if (null == paraBean || null == recordBean || (StringUtils.isBlank(paraBean.getProductSysCode()) && CollectionUtils.isEmpty(paraBean.getProductSysCodeList())) ) {
            return false;
        }
        recordBean.setUpdateTime(UtilDate.getDate());
        ProductChannelGoodsPriceExample example = new ProductChannelGoodsPriceExample();
        getSearchData(paraBean, example);
        if (example.getOredCriteria().isEmpty()){
            return false;
        }
        return productChannelGoodsPriceMapper.updateByExampleSelective(recordBean, example) > 0;
    }

    /**
     * 入参拼接
     *
     * @param paraBean
     * @param example
     */
    public void getSearchData(ParaProductChannelGoodsPriceBean paraBean, ProductChannelGoodsPriceExample example) {
        if (null == example || null == paraBean) {
            return;
        }
        ProductChannelGoodsPriceExample.Criteria criteria = example.createCriteria();
        // 站点编码
        if (StringUtils.isNotBlank(paraBean.getSiteCode())) {
            criteria.andSiteCodeEqualTo(paraBean.getSiteCode());
        }
        // 平台商品编码
        if (StringUtils.isNotBlank(paraBean.getProductSysCode())) {
            criteria.andProductSysCodeEqualTo(paraBean.getProductSysCode());
        }
        if (CollectionUtils.isNotEmpty(paraBean.getProductSysCodeList())) {
            criteria.andProductSysCodeIn(paraBean.getProductSysCodeList());
        }
    }

}
